package com.pfsoft.grpcserver.service.impl;

import com.pfsoft.grpcserver.common.enums.ErrorMsg;
import com.pfsoft.grpcserver.common.enums.RespCodeEnum;
import com.pfsoft.grpcserver.common.exception.BusinessException;
import com.pfsoft.grpcserver.domain.TbOrderInfo;
import com.pfsoft.grpcserver.example.TbOrderInfoExample;
import com.pfsoft.grpcserver.mapper.TbOrderInfoMapper;
import com.pfsoft.grpcserver.service.IOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author pengfei
 * @date 2022年06月28日 11:21
 */
@Slf4j
@Service
public class OrderInfoServiceImpl implements IOrderInfoService {

    @Autowired
    private TbOrderInfoMapper tbOrderInfoMapper;

    @Override
    public int save(TbOrderInfo tbOrderInfo) {
        return tbOrderInfoMapper.insertSelective(tbOrderInfo);
    }

    @Override
    public List<TbOrderInfo> getAll() {
        return tbOrderInfoMapper.selectByExample(new TbOrderInfoExample());
    }

    @Override
    public TbOrderInfo queryByOrderId(String orderId) {
        TbOrderInfoExample example = new TbOrderInfoExample();
        example.createCriteria().andOrderIdEqualTo(orderId);
        List<TbOrderInfo> tbOrderInfos = tbOrderInfoMapper.selectByExample(example);
        if (tbOrderInfos.size() <= 0) {
//            log.error("订单不存在，请检查查询条件是否正确，orderId:【{}】",orderId);
            throw  new BusinessException(RespCodeEnum.BIZ_EXCEPTION, ErrorMsg.ORDER_NOT_EXIST.getMsg());
        }
        return tbOrderInfos.get(0);
    }
}
